package com.sita.bike.rest.model;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

/**
 * Created by manhongyun on 15/11/12.
 */
public class Account implements Serializable {
    @SerializedName("accountId")
    public String mAccountId;
    @SerializedName("uniqueId")
    public String mUniqueId;
    @SerializedName("mobile")
    public String mMobile;
    @SerializedName("email")
    public String mEmail;
    @SerializedName("avatar")
    public String mAvatar;
    @SerializedName("nickName")
    public String mNickName;
    @SerializedName("signature")
    public String mSignature;
    @SerializedName("imId")
    public String mImId;
    @SerializedName("imPwd")
    public String mImPwd;
    @SerializedName("birthday")
    public String mBirthday;
    @SerializedName("gender")
    public int mGender = 0;
    @SerializedName("address")
    public String mAddress;
    @SerializedName("lng")
    public String mLng;
    @SerializedName("lat")
    public String mLat;
    @SerializedName("geoTime")
    public Long mGeoTime;
    @SerializedName("province")
    public String mProvince;
    @SerializedName("city")
    public String mCity;

    @Expose
    public double distanceToMe = 0d;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Account account = (Account) o;

        if (mGender != account.mGender) return false;
        if (!mAccountId.equals(account.mAccountId)) return false;
        if (mUniqueId != null ? !mUniqueId.equals(account.mUniqueId) : account.mUniqueId != null)
            return false;
        if (mMobile != null ? !mMobile.equals(account.mMobile) : account.mMobile != null)
            return false;
        if (mEmail != null ? !mEmail.equals(account.mEmail) : account.mEmail != null) return false;
        if (mAvatar != null ? !mAvatar.equals(account.mAvatar) : account.mAvatar != null)
            return false;
        if (mNickName != null ? !mNickName.equals(account.mNickName) : account.mNickName != null)
            return false;
        if (mSignature != null ? !mSignature.equals(account.mSignature) : account.mSignature != null)
            return false;
        if (mImId != null ? !mImId.equals(account.mImId) : account.mImId != null) return false;
        if (mImPwd != null ? !mImPwd.equals(account.mImPwd) : account.mImPwd != null) return false;
        if (mBirthday != null ? !mBirthday.equals(account.mBirthday) : account.mBirthday != null)
            return false;
        if (mAddress != null ? !mAddress.equals(account.mAddress) : account.mAddress != null)
            return false;
        if (mLng != null ? !mLng.equals(account.mLng) : account.mLng != null) return false;
        if (mLat != null ? !mLat.equals(account.mLat) : account.mLat != null) return false;
        if (mGeoTime != null ? !mGeoTime.equals(account.mGeoTime) : account.mGeoTime != null)
            return false;
        if (mProvince != null ? !mProvince.equals(account.mProvince) : account.mProvince != null)
            return false;
        return !(mCity != null ? !mCity.equals(account.mCity) : account.mCity != null);

    }

    @Override
    public int hashCode() {
        int result = mAccountId.hashCode();
        result = 31 * result + (mUniqueId != null ? mUniqueId.hashCode() : 0);
        result = 31 * result + (mMobile != null ? mMobile.hashCode() : 0);
        result = 31 * result + (mEmail != null ? mEmail.hashCode() : 0);
        result = 31 * result + (mAvatar != null ? mAvatar.hashCode() : 0);
        result = 31 * result + (mNickName != null ? mNickName.hashCode() : 0);
        result = 31 * result + (mSignature != null ? mSignature.hashCode() : 0);
        result = 31 * result + (mImId != null ? mImId.hashCode() : 0);
        result = 31 * result + (mImPwd != null ? mImPwd.hashCode() : 0);
        result = 31 * result + (mBirthday != null ? mBirthday.hashCode() : 0);
        result = 31 * result + mGender;
        result = 31 * result + (mAddress != null ? mAddress.hashCode() : 0);
        result = 31 * result + (mLng != null ? mLng.hashCode() : 0);
        result = 31 * result + (mLat != null ? mLat.hashCode() : 0);
        result = 31 * result + (mGeoTime != null ? mGeoTime.hashCode() : 0);
        result = 31 * result + (mProvince != null ? mProvince.hashCode() : 0);
        result = 31 * result + (mCity != null ? mCity.hashCode() : 0);
        return result;
    }

    public String toString(){
        Gson gson = new GsonBuilder().serializeNulls().create();
        return gson.toJson(this);
    }

    public static Account parse(String string){
        Gson gson = new GsonBuilder().serializeNulls().create();
        Account account = gson.fromJson(string, Account.class);
        return account;
    }
}
